﻿using System;
using System.Web.Security;
using NetDon.OA.Interface;
using NetDon.Utilities;



namespace NetDon.OA.Portal
{
    public partial class _Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //txtUserName.Text = "admin";

                //txtPassword.Attributes.Add("value", "admin");
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Trim().Length == 0)
            {
                lblMessage.Text = "请输入用户名.";
                return;
            }
            if (txtPassword.Text.Trim().Length == 0)
            {
                lblMessage.Text = "请输入密码.";
                return;
            }
            string userName = txtUserName.Text.Trim();
            var service = ServiceContainer.GetService<ISecurityService>();
            string message = string.Empty;
            if (service.ValidateUser(userName, txtPassword.Text.Trim(), out message))
            {
                FormsAuthentication.SetAuthCookie(userName, true);
                Response.Redirect("~/");
            }
            else
            {
                lblMessage.Text = message;
                return;
            }
        }
    }
}
